package org.facilscrum.persistencia;

import org.facilscrum.beans.Tareas;
import java.sql.Date; 
import org.facilscrum.beans.*;
import org.facilscrum.controller.*;
import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;
import java.util.*;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.util.Map;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;
 import javax.sql.DataSource;
import org.facilscrum.generales.Mensajeria;
import org.facilscrum.generales.DataGManager;


/**
*
* @author
*/

public class TareasPersistencia implements Serializable {
private static final long serialVersionUID = 1L;
public static Exception excepcion;
public static boolean esMensaje = false;
public static Connection con = null;
public static java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/facilscrum/properties/mensajes");
static DataGManager dataGManager;
static List<Tareas> list;

public TareasPersistencia(){
         esMensaje =false;
}



/**
*
* insert()
*/

public static boolean insert (Tareas tareas ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pinsert = null;
      String sql = "insert into tareas(task,descripcion,iduserstories,duracion,username,idestatustareas,fecha)  values(?,?,?,?,?,?,?)";
      pinsert = con.prepareStatement(sql);
              pinsert.setString(1,tareas.getTask());
        pinsert.setString(2,tareas.getDescripcion());
        pinsert.setInt(3,tareas.getIduserstories());
        pinsert.setInt(4,tareas.getDuracion());
        pinsert.setString(5,tareas.getUsername());
        pinsert.setString(6,tareas.getIdestatustareas());
        pinsert.setDate(7,tareas.getFecha());
      int filas= pinsert.executeUpdate();
      pinsert.close();
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
 }


/**
*
* update()
*/

public static boolean update(Tareas tareas ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update tareas set  task=?, descripcion=?, iduserstories=?, duracion=?, username=?, idestatustareas=?, fecha=?  where  idtarea ='"+tareas.getIdtarea()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setString(1,tareas.getTask());
pupdate.setString(2,tareas.getDescripcion());
pupdate.setInt(3,tareas.getIduserstories());
pupdate.setInt(4,tareas.getDuracion());
pupdate.setString(5,tareas.getUsername());
pupdate.setString(6,tareas.getIdestatustareas());
pupdate.setDate(7,tareas.getFecha());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* update()
*/

public static boolean update(String sqlupdate ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update  tareas set " + sqlupdate +"";
      pupdate= con.prepareStatement(sql);
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* updatePrimaryKey()
*/

public static boolean updatePrimaryKey(Tareas tareas_old , Tareas tareas) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update tareas set  idtarea=?  where  idtarea ='"+tareas_old.getIdtarea()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setInt(0,tareas.getIdtarea());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(Tareas tareas ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from tareas  where  idtarea = ?  ";
      pdelete= con.prepareStatement(sql);
      pdelete.setInt(1,tareas.getIdtarea());
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(String sqldelete ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from tareas where " + sqldelete +"";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* deleteAll()
*/

public static boolean deleteAll() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from tareas  ";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodeleteall"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* exists()
*/



public static boolean exists(Tareas tareas) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      String sql = "select * from tareas where idtarea='"+tareas.getIdtarea()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "tareas" +" " + bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return false;
   }
    rs.close();
    psquery.close();
 return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* findByPrimaryKey()
*/



public static Tareas findByPrimaryKey(Tareas tareas) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      String sql = "select * from tareas where idtarea='"+tareas.getIdtarea()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "tareas" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Estatustareas estatustareas = new Estatustareas();
Estatustareas estatustareas2 = new Estatustareas();
EstatustareasController estatustareasController = new EstatustareasController();
Userstories userstories = new Userstories();
Userstories userstories2 = new Userstories();
UserstoriesController userstoriesController = new UserstoriesController();
Usuarios usuarios = new Usuarios();
Usuarios usuarios2 = new Usuarios();
UsuariosController usuariosController = new UsuariosController();
            
    estatustareas.setIdestatustareas(rs.getString("idestatustareas"));
    userstories.setIduserstories(rs.getInt("iduserstories"));
    usuarios.setUsername(rs.getString("username"));
            
   estatustareas2 =  estatustareasController.findByPrimaryKey(estatustareas);
   if (estatustareas2== null) {
       //no existe registro con ese codigo 
   } else {
   estatustareas= estatustareas2;
   tareas.setEstatustareas(estatustareas);
     }
   userstories2 =  userstoriesController.findByPrimaryKey(userstories);
   if (userstories2== null) {
       //no existe registro con ese codigo 
   } else {
   userstories= userstories2;
   tareas.setUserstories(userstories);
     }
   usuarios2 =  usuariosController.findByPrimaryKey(usuarios);
   if (usuarios2== null) {
       //no existe registro con ese codigo 
   } else {
   usuarios= usuarios2;
   tareas.setUsuarios(usuarios);
     }
            tareas.setIdtarea(rs.getInt("idtarea"));
tareas.setTask(rs.getString("task"));
tareas.setDescripcion(rs.getString("descripcion"));
tareas.setIduserstories(rs.getInt("iduserstories"));
tareas.setDuracion(rs.getInt("duracion"));
tareas.setUsername(rs.getString("username"));
tareas.setIdestatustareas(rs.getString("idestatustareas"));
tareas.setFecha(rs.getDate("fecha"));
    }
    rs.close();
    psquery.close();
 return tareas;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return null;
}


/**
*
* findByIdtarea()
*/

public static List<Tareas> findByIdtarea(Tareas tareas,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<>();
      String sql = "select * from tareas where idtarea='"+tareas.getIdtarea()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "tareas" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Estatustareas estatustareas = new Estatustareas();
Estatustareas estatustareas2 = new Estatustareas();
EstatustareasController estatustareasController = new EstatustareasController();
Userstories userstories = new Userstories();
Userstories userstories2 = new Userstories();
UserstoriesController userstoriesController = new UserstoriesController();
Usuarios usuarios = new Usuarios();
Usuarios usuarios2 = new Usuarios();
UsuariosController usuariosController = new UsuariosController();
        Tareas tareas2 = new Tareas(
         rs.getInt("idtarea"),rs.getString("task"),rs.getString("descripcion"),rs.getInt("iduserstories"),rs.getInt("duracion"),rs.getString("username"),rs.getString("idestatustareas"),rs.getDate("fecha"));
            
    estatustareas.setIdestatustareas(rs.getString("idestatustareas"));
    userstories.setIduserstories(rs.getInt("iduserstories"));
    usuarios.setUsername(rs.getString("username"));
            
  if(withRelation){
     estatustareas2 =  estatustareasController.findByPrimaryKey(estatustareas);
     if (estatustareas2== null) {
       //not found records 
     } else {
     estatustareas= estatustareas2;
     tareas2.setEstatustareas(estatustareas);
       }
   }
  if(withRelation){
     userstories2 =  userstoriesController.findByPrimaryKey(userstories);
     if (userstories2== null) {
       //not found records 
     } else {
     userstories= userstories2;
     tareas2.setUserstories(userstories);
       }
   }
  if(withRelation){
     usuarios2 =  usuariosController.findByPrimaryKey(usuarios);
     if (usuarios2== null) {
       //not found records 
     } else {
     usuarios= usuarios2;
     tareas2.setUsuarios(usuarios);
       }
   }
       list.add(tareas2);
    }
    rs.close();
    psquery.close();
    return list;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return null;
}


/**
*
* findByTask()
*/

public static List<Tareas> findByTask(Tareas tareas,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<>();
      String sql = "select * from tareas where task='"+tareas.getTask()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "tareas" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Estatustareas estatustareas = new Estatustareas();
Estatustareas estatustareas2 = new Estatustareas();
EstatustareasController estatustareasController = new EstatustareasController();
Userstories userstories = new Userstories();
Userstories userstories2 = new Userstories();
UserstoriesController userstoriesController = new UserstoriesController();
Usuarios usuarios = new Usuarios();
Usuarios usuarios2 = new Usuarios();
UsuariosController usuariosController = new UsuariosController();
        Tareas tareas2 = new Tareas(
         rs.getInt("idtarea"),rs.getString("task"),rs.getString("descripcion"),rs.getInt("iduserstories"),rs.getInt("duracion"),rs.getString("username"),rs.getString("idestatustareas"),rs.getDate("fecha"));
            
    estatustareas.setIdestatustareas(rs.getString("idestatustareas"));
    userstories.setIduserstories(rs.getInt("iduserstories"));
    usuarios.setUsername(rs.getString("username"));
            
  if(withRelation){
     estatustareas2 =  estatustareasController.findByPrimaryKey(estatustareas);
     if (estatustareas2== null) {
       //not found records 
     } else {
     estatustareas= estatustareas2;
     tareas2.setEstatustareas(estatustareas);
       }
   }
  if(withRelation){
     userstories2 =  userstoriesController.findByPrimaryKey(userstories);
     if (userstories2== null) {
       //not found records 
     } else {
     userstories= userstories2;
     tareas2.setUserstories(userstories);
       }
   }
  if(withRelation){
     usuarios2 =  usuariosController.findByPrimaryKey(usuarios);
     if (usuarios2== null) {
       //not found records 
     } else {
     usuarios= usuarios2;
     tareas2.setUsuarios(usuarios);
       }
   }
       list.add(tareas2);
    }
    rs.close();
    psquery.close();
    return list;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return null;
}


/**
*
* findByDescripcion()
*/

public static List<Tareas> findByDescripcion(Tareas tareas,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<>();
      String sql = "select * from tareas where descripcion='"+tareas.getDescripcion()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "tareas" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Estatustareas estatustareas = new Estatustareas();
Estatustareas estatustareas2 = new Estatustareas();
EstatustareasController estatustareasController = new EstatustareasController();
Userstories userstories = new Userstories();
Userstories userstories2 = new Userstories();
UserstoriesController userstoriesController = new UserstoriesController();
Usuarios usuarios = new Usuarios();
Usuarios usuarios2 = new Usuarios();
UsuariosController usuariosController = new UsuariosController();
        Tareas tareas2 = new Tareas(
         rs.getInt("idtarea"),rs.getString("task"),rs.getString("descripcion"),rs.getInt("iduserstories"),rs.getInt("duracion"),rs.getString("username"),rs.getString("idestatustareas"),rs.getDate("fecha"));
            
    estatustareas.setIdestatustareas(rs.getString("idestatustareas"));
    userstories.setIduserstories(rs.getInt("iduserstories"));
    usuarios.setUsername(rs.getString("username"));
            
  if(withRelation){
     estatustareas2 =  estatustareasController.findByPrimaryKey(estatustareas);
     if (estatustareas2== null) {
       //not found records 
     } else {
     estatustareas= estatustareas2;
     tareas2.setEstatustareas(estatustareas);
       }
   }
  if(withRelation){
     userstories2 =  userstoriesController.findByPrimaryKey(userstories);
     if (userstories2== null) {
       //not found records 
     } else {
     userstories= userstories2;
     tareas2.setUserstories(userstories);
       }
   }
  if(withRelation){
     usuarios2 =  usuariosController.findByPrimaryKey(usuarios);
     if (usuarios2== null) {
       //not found records 
     } else {
     usuarios= usuarios2;
     tareas2.setUsuarios(usuarios);
       }
   }
       list.add(tareas2);
    }
    rs.close();
    psquery.close();
    return list;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return null;
}


/**
*
* findByIduserstories()
*/

public static List<Tareas> findByIduserstories(Tareas tareas,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<>();
      String sql = "select * from tareas where iduserstories='"+tareas.getIduserstories()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "tareas" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Estatustareas estatustareas = new Estatustareas();
Estatustareas estatustareas2 = new Estatustareas();
EstatustareasController estatustareasController = new EstatustareasController();
Userstories userstories = new Userstories();
Userstories userstories2 = new Userstories();
UserstoriesController userstoriesController = new UserstoriesController();
Usuarios usuarios = new Usuarios();
Usuarios usuarios2 = new Usuarios();
UsuariosController usuariosController = new UsuariosController();
        Tareas tareas2 = new Tareas(
         rs.getInt("idtarea"),rs.getString("task"),rs.getString("descripcion"),rs.getInt("iduserstories"),rs.getInt("duracion"),rs.getString("username"),rs.getString("idestatustareas"),rs.getDate("fecha"));
            
    estatustareas.setIdestatustareas(rs.getString("idestatustareas"));
    userstories.setIduserstories(rs.getInt("iduserstories"));
    usuarios.setUsername(rs.getString("username"));
            
  if(withRelation){
     estatustareas2 =  estatustareasController.findByPrimaryKey(estatustareas);
     if (estatustareas2== null) {
       //not found records 
     } else {
     estatustareas= estatustareas2;
     tareas2.setEstatustareas(estatustareas);
       }
   }
  if(withRelation){
     userstories2 =  userstoriesController.findByPrimaryKey(userstories);
     if (userstories2== null) {
       //not found records 
     } else {
     userstories= userstories2;
     tareas2.setUserstories(userstories);
       }
   }
  if(withRelation){
     usuarios2 =  usuariosController.findByPrimaryKey(usuarios);
     if (usuarios2== null) {
       //not found records 
     } else {
     usuarios= usuarios2;
     tareas2.setUsuarios(usuarios);
       }
   }
       list.add(tareas2);
    }
    rs.close();
    psquery.close();
    return list;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return null;
}


/**
*
* findByDuracion()
*/

public static List<Tareas> findByDuracion(Tareas tareas,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<>();
      String sql = "select * from tareas where duracion='"+tareas.getDuracion()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "tareas" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Estatustareas estatustareas = new Estatustareas();
Estatustareas estatustareas2 = new Estatustareas();
EstatustareasController estatustareasController = new EstatustareasController();
Userstories userstories = new Userstories();
Userstories userstories2 = new Userstories();
UserstoriesController userstoriesController = new UserstoriesController();
Usuarios usuarios = new Usuarios();
Usuarios usuarios2 = new Usuarios();
UsuariosController usuariosController = new UsuariosController();
        Tareas tareas2 = new Tareas(
         rs.getInt("idtarea"),rs.getString("task"),rs.getString("descripcion"),rs.getInt("iduserstories"),rs.getInt("duracion"),rs.getString("username"),rs.getString("idestatustareas"),rs.getDate("fecha"));
            
    estatustareas.setIdestatustareas(rs.getString("idestatustareas"));
    userstories.setIduserstories(rs.getInt("iduserstories"));
    usuarios.setUsername(rs.getString("username"));
            
  if(withRelation){
     estatustareas2 =  estatustareasController.findByPrimaryKey(estatustareas);
     if (estatustareas2== null) {
       //not found records 
     } else {
     estatustareas= estatustareas2;
     tareas2.setEstatustareas(estatustareas);
       }
   }
  if(withRelation){
     userstories2 =  userstoriesController.findByPrimaryKey(userstories);
     if (userstories2== null) {
       //not found records 
     } else {
     userstories= userstories2;
     tareas2.setUserstories(userstories);
       }
   }
  if(withRelation){
     usuarios2 =  usuariosController.findByPrimaryKey(usuarios);
     if (usuarios2== null) {
       //not found records 
     } else {
     usuarios= usuarios2;
     tareas2.setUsuarios(usuarios);
       }
   }
       list.add(tareas2);
    }
    rs.close();
    psquery.close();
    return list;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return null;
}


/**
*
* findByUsername()
*/

public static List<Tareas> findByUsername(Tareas tareas,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<>();
      String sql = "select * from tareas where username='"+tareas.getUsername()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "tareas" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Estatustareas estatustareas = new Estatustareas();
Estatustareas estatustareas2 = new Estatustareas();
EstatustareasController estatustareasController = new EstatustareasController();
Userstories userstories = new Userstories();
Userstories userstories2 = new Userstories();
UserstoriesController userstoriesController = new UserstoriesController();
Usuarios usuarios = new Usuarios();
Usuarios usuarios2 = new Usuarios();
UsuariosController usuariosController = new UsuariosController();
        Tareas tareas2 = new Tareas(
         rs.getInt("idtarea"),rs.getString("task"),rs.getString("descripcion"),rs.getInt("iduserstories"),rs.getInt("duracion"),rs.getString("username"),rs.getString("idestatustareas"),rs.getDate("fecha"));
            
    estatustareas.setIdestatustareas(rs.getString("idestatustareas"));
    userstories.setIduserstories(rs.getInt("iduserstories"));
    usuarios.setUsername(rs.getString("username"));
            
  if(withRelation){
     estatustareas2 =  estatustareasController.findByPrimaryKey(estatustareas);
     if (estatustareas2== null) {
       //not found records 
     } else {
     estatustareas= estatustareas2;
     tareas2.setEstatustareas(estatustareas);
       }
   }
  if(withRelation){
     userstories2 =  userstoriesController.findByPrimaryKey(userstories);
     if (userstories2== null) {
       //not found records 
     } else {
     userstories= userstories2;
     tareas2.setUserstories(userstories);
       }
   }
  if(withRelation){
     usuarios2 =  usuariosController.findByPrimaryKey(usuarios);
     if (usuarios2== null) {
       //not found records 
     } else {
     usuarios= usuarios2;
     tareas2.setUsuarios(usuarios);
       }
   }
       list.add(tareas2);
    }
    rs.close();
    psquery.close();
    return list;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return null;
}


/**
*
* findByIdestatustareas()
*/

public static List<Tareas> findByIdestatustareas(Tareas tareas,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<>();
      String sql = "select * from tareas where idestatustareas='"+tareas.getIdestatustareas()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "tareas" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Estatustareas estatustareas = new Estatustareas();
Estatustareas estatustareas2 = new Estatustareas();
EstatustareasController estatustareasController = new EstatustareasController();
Userstories userstories = new Userstories();
Userstories userstories2 = new Userstories();
UserstoriesController userstoriesController = new UserstoriesController();
Usuarios usuarios = new Usuarios();
Usuarios usuarios2 = new Usuarios();
UsuariosController usuariosController = new UsuariosController();
        Tareas tareas2 = new Tareas(
         rs.getInt("idtarea"),rs.getString("task"),rs.getString("descripcion"),rs.getInt("iduserstories"),rs.getInt("duracion"),rs.getString("username"),rs.getString("idestatustareas"),rs.getDate("fecha"));
            
    estatustareas.setIdestatustareas(rs.getString("idestatustareas"));
    userstories.setIduserstories(rs.getInt("iduserstories"));
    usuarios.setUsername(rs.getString("username"));
            
  if(withRelation){
     estatustareas2 =  estatustareasController.findByPrimaryKey(estatustareas);
     if (estatustareas2== null) {
       //not found records 
     } else {
     estatustareas= estatustareas2;
     tareas2.setEstatustareas(estatustareas);
       }
   }
  if(withRelation){
     userstories2 =  userstoriesController.findByPrimaryKey(userstories);
     if (userstories2== null) {
       //not found records 
     } else {
     userstories= userstories2;
     tareas2.setUserstories(userstories);
       }
   }
  if(withRelation){
     usuarios2 =  usuariosController.findByPrimaryKey(usuarios);
     if (usuarios2== null) {
       //not found records 
     } else {
     usuarios= usuarios2;
     tareas2.setUsuarios(usuarios);
       }
   }
       list.add(tareas2);
    }
    rs.close();
    psquery.close();
    return list;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return null;
}


/**
*
* findByFecha()
*/

public static List<Tareas> findByFecha(Tareas tareas,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<>();
      String sql = "select * from tareas where fecha='"+tareas.getFecha()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "tareas" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Estatustareas estatustareas = new Estatustareas();
Estatustareas estatustareas2 = new Estatustareas();
EstatustareasController estatustareasController = new EstatustareasController();
Userstories userstories = new Userstories();
Userstories userstories2 = new Userstories();
UserstoriesController userstoriesController = new UserstoriesController();
Usuarios usuarios = new Usuarios();
Usuarios usuarios2 = new Usuarios();
UsuariosController usuariosController = new UsuariosController();
        Tareas tareas2 = new Tareas(
         rs.getInt("idtarea"),rs.getString("task"),rs.getString("descripcion"),rs.getInt("iduserstories"),rs.getInt("duracion"),rs.getString("username"),rs.getString("idestatustareas"),rs.getDate("fecha"));
            
    estatustareas.setIdestatustareas(rs.getString("idestatustareas"));
    userstories.setIduserstories(rs.getInt("iduserstories"));
    usuarios.setUsername(rs.getString("username"));
            
  if(withRelation){
     estatustareas2 =  estatustareasController.findByPrimaryKey(estatustareas);
     if (estatustareas2== null) {
       //not found records 
     } else {
     estatustareas= estatustareas2;
     tareas2.setEstatustareas(estatustareas);
       }
   }
  if(withRelation){
     userstories2 =  userstoriesController.findByPrimaryKey(userstories);
     if (userstories2== null) {
       //not found records 
     } else {
     userstories= userstories2;
     tareas2.setUserstories(userstories);
       }
   }
  if(withRelation){
     usuarios2 =  usuariosController.findByPrimaryKey(usuarios);
     if (usuarios2== null) {
       //not found records 
     } else {
     usuarios= usuarios2;
     tareas2.setUsuarios(usuarios);
       }
   }
       list.add(tareas2);
    }
    rs.close();
    psquery.close();
    return list;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return null;
}


/**
*
* locateByParameters()
*/

public static List<Tareas> locateByParameters(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<>();
  String sql = "select * from tareas";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      int i = 0;
      while (it.hasNext()) {
          if (i != 0){
            sb.append(" and ");
         }
         i++;
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"= '"+  e.getValue()+"'");
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "tareas" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Estatustareas estatustareas = new Estatustareas();
Estatustareas estatustareas2 = new Estatustareas();
EstatustareasController estatustareasController = new EstatustareasController();
Userstories userstories = new Userstories();
Userstories userstories2 = new Userstories();
UserstoriesController userstoriesController = new UserstoriesController();
Usuarios usuarios = new Usuarios();
Usuarios usuarios2 = new Usuarios();
UsuariosController usuariosController = new UsuariosController();
        Tareas tareas2 = new Tareas(
         rs.getInt("idtarea"),rs.getString("task"),rs.getString("descripcion"),rs.getInt("iduserstories"),rs.getInt("duracion"),rs.getString("username"),rs.getString("idestatustareas"),rs.getDate("fecha"));
            
    estatustareas.setIdestatustareas(rs.getString("idestatustareas"));
    userstories.setIduserstories(rs.getInt("iduserstories"));
    usuarios.setUsername(rs.getString("username"));
            
  if(withRelation){
     estatustareas2 =  estatustareasController.findByPrimaryKey(estatustareas);
     if (estatustareas2== null) {
       //not found records 
     } else {
     estatustareas= estatustareas2;
     tareas2.setEstatustareas(estatustareas);
       }
   }
  if(withRelation){
     userstories2 =  userstoriesController.findByPrimaryKey(userstories);
     if (userstories2== null) {
       //not found records 
     } else {
     userstories= userstories2;
     tareas2.setUserstories(userstories);
       }
   }
  if(withRelation){
     usuarios2 =  usuariosController.findByPrimaryKey(usuarios);
     if (usuarios2== null) {
       //not found records 
     } else {
     usuarios= usuarios2;
     tareas2.setUsuarios(usuarios);
       }
   }
       list.add(tareas2);
    }
    rs.close();
    psquery.close();
    return list;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return null;
}


/**
*
* Double func(String funcion, String campo)
*/



public static Double func(String funcion, String campo) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from tareas";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "tareas" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return 0.0;
}


/**
*
* Double func(String funcion, String campo,String where)
*/



public static Double func(String funcion, String campo, String where) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from tareas where "+where +" ";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "tareas" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return 0.0;
}


/**
*
* count()
*/



public static Integer count() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from tareas";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "tareas" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
     rs.beforeFirst();
     while (rs.next()) {
      x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return 0;
}


/**
*
* count(String sqlquery)
*/



public static Integer count(String sqlquery) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from tareas where  " + sqlquery +"";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "tareas" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return 0;
}


/**
*
* query()
*/

public static List<Tareas> query(String query,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<>();
  String sql = "select * from tareas where " + query +"";
  if (query == null || query.equals("")) {
  return null;
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "tareas" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Estatustareas estatustareas = new Estatustareas();
Estatustareas estatustareas2 = new Estatustareas();
EstatustareasController estatustareasController = new EstatustareasController();
Userstories userstories = new Userstories();
Userstories userstories2 = new Userstories();
UserstoriesController userstoriesController = new UserstoriesController();
Usuarios usuarios = new Usuarios();
Usuarios usuarios2 = new Usuarios();
UsuariosController usuariosController = new UsuariosController();
        Tareas tareas2 = new Tareas(
         rs.getInt("idtarea"),rs.getString("task"),rs.getString("descripcion"),rs.getInt("iduserstories"),rs.getInt("duracion"),rs.getString("username"),rs.getString("idestatustareas"),rs.getDate("fecha"));
            
    estatustareas.setIdestatustareas(rs.getString("idestatustareas"));
    userstories.setIduserstories(rs.getInt("iduserstories"));
    usuarios.setUsername(rs.getString("username"));
            
  if(withRelation){
     estatustareas2 =  estatustareasController.findByPrimaryKey(estatustareas);
     if (estatustareas2== null) {
       //not found records 
     } else {
     estatustareas= estatustareas2;
     tareas2.setEstatustareas(estatustareas);
       }
   }
  if(withRelation){
     userstories2 =  userstoriesController.findByPrimaryKey(userstories);
     if (userstories2== null) {
       //not found records 
     } else {
     userstories= userstories2;
     tareas2.setUserstories(userstories);
       }
   }
  if(withRelation){
     usuarios2 =  usuariosController.findByPrimaryKey(usuarios);
     if (usuarios2== null) {
       //not found records 
     } else {
     usuarios= usuarios2;
     tareas2.setUsuarios(usuarios);
       }
   }
       list.add(tareas2);
    }
    rs.close();
    psquery.close();
    return list;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return null;
}


/**
*
* orderby()
*/

public static List<Tareas> orderby(String query,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<>();
  String sql = "select * from tareas order by " + query +"";
  if (query == null || query.equals("")) {
  return null;
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "tareas" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Estatustareas estatustareas = new Estatustareas();
Estatustareas estatustareas2 = new Estatustareas();
EstatustareasController estatustareasController = new EstatustareasController();
Userstories userstories = new Userstories();
Userstories userstories2 = new Userstories();
UserstoriesController userstoriesController = new UserstoriesController();
Usuarios usuarios = new Usuarios();
Usuarios usuarios2 = new Usuarios();
UsuariosController usuariosController = new UsuariosController();
        Tareas tareas2 = new Tareas(
         rs.getInt("idtarea"),rs.getString("task"),rs.getString("descripcion"),rs.getInt("iduserstories"),rs.getInt("duracion"),rs.getString("username"),rs.getString("idestatustareas"),rs.getDate("fecha"));
            
    estatustareas.setIdestatustareas(rs.getString("idestatustareas"));
    userstories.setIduserstories(rs.getInt("iduserstories"));
    usuarios.setUsername(rs.getString("username"));
            
  if(withRelation){
     estatustareas2 =  estatustareasController.findByPrimaryKey(estatustareas);
     if (estatustareas2== null) {
       //not found records 
     } else {
     estatustareas= estatustareas2;
     tareas2.setEstatustareas(estatustareas);
       }
   }
  if(withRelation){
     userstories2 =  userstoriesController.findByPrimaryKey(userstories);
     if (userstories2== null) {
       //not found records 
     } else {
     userstories= userstories2;
     tareas2.setUserstories(userstories);
       }
   }
  if(withRelation){
     usuarios2 =  usuariosController.findByPrimaryKey(usuarios);
     if (usuarios2== null) {
       //not found records 
     } else {
     usuarios= usuarios2;
     tareas2.setUsuarios(usuarios);
       }
   }
       list.add(tareas2);
    }
    rs.close();
    psquery.close();
    return list;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return null;
}


/**
*
* getListRecords()
*/

public static List<Tareas> getListRecords(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<>();
  String sql = "select * from tareas";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      while (it.hasNext()) {
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"="+  e.getValue());
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "tareas" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
       
Estatustareas estatustareas = new Estatustareas();
Estatustareas estatustareas2 = new Estatustareas();
EstatustareasController estatustareasController = new EstatustareasController();
Userstories userstories = new Userstories();
Userstories userstories2 = new Userstories();
UserstoriesController userstoriesController = new UserstoriesController();
Usuarios usuarios = new Usuarios();
Usuarios usuarios2 = new Usuarios();
UsuariosController usuariosController = new UsuariosController();
        Tareas tareas2 = new Tareas(
         rs.getInt("idtarea"),rs.getString("task"),rs.getString("descripcion"),rs.getInt("iduserstories"),rs.getInt("duracion"),rs.getString("username"),rs.getString("idestatustareas"),rs.getDate("fecha"));
            
    estatustareas.setIdestatustareas(rs.getString("idestatustareas"));
    userstories.setIduserstories(rs.getInt("iduserstories"));
    usuarios.setUsername(rs.getString("username"));
            
  if(withRelation){
     estatustareas2 =  estatustareasController.findByPrimaryKey(estatustareas);
     if (estatustareas2== null) {
       //not found records 
     } else {
     estatustareas= estatustareas2;
     tareas2.setEstatustareas(estatustareas);
       }
   }
  if(withRelation){
     userstories2 =  userstoriesController.findByPrimaryKey(userstories);
     if (userstories2== null) {
       //not found records 
     } else {
     userstories= userstories2;
     tareas2.setUserstories(userstories);
       }
   }
  if(withRelation){
     usuarios2 =  usuariosController.findByPrimaryKey(usuarios);
     if (usuarios2== null) {
       //not found records 
     } else {
     usuarios= usuarios2;
     tareas2.setUsuarios(usuarios);
       }
   }
       list.add(tareas2);
    }
    rs.close();
    psquery.close();
    return list;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return null;
 }


}
